package com.warren.biz.controller;


import com.warren.annotation.ControllerEndpoint;
import com.warren.biz.entity.ProductCategory;
import com.warren.biz.service.ProductCategoryService;
import com.warren.response.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jdk.internal.org.objectweb.asm.tree.analysis.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.sql.ResultSet;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author warren
 * @since 2021-04-20
 */
@Api(value ="物资类别",tags = "物资类别接口")
@RestController
@RequestMapping("/biz/productCategory")
public class ProductCategoryController {

    @Resource
    private ProductCategoryService productCategoryService;

    @ApiOperation(value = "查询所有物资类别列表")
    @GetMapping("/getList")
    public Result getCategory() throws  CloneNotSupportedException{
        List<ProductCategory> productCategories = productCategoryService.categoryTreeBuild(productCategoryService.getAll());
        return Result.ok().data("menus",productCategories);
    }

    @ControllerEndpoint(exceptionMessage = "添加物资分类失败",operation = "添加物资分类")
    @ApiOperation(value = "添加物资分类")
    @PostMapping("/addCategory")
    public Result addCategory(@RequestBody ProductCategory category){
        productCategoryService.add(category);
        return Result.ok();
    }

    @ControllerEndpoint(exceptionMessage = "修改物资分类失败",operation = "修改物资分类")
    @ApiOperation(value = "修改物资分类")
    @PutMapping("/updateCategory")
    public Result updateCategory(@RequestBody ProductCategory category){
        productCategoryService.updateMenu(category);
        return Result.ok();
    }

    @ControllerEndpoint(exceptionMessage = "删除物资分类失败",operation = "删除物资分类")
    @ApiOperation(value = "删除物资分类")
    @DeleteMapping("/delCategory")
    public Result delCategory(Long id){
        productCategoryService.delMenu(id);
        return Result.ok();
    }
}

